package rpg.visual.window;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;

import pgui.PVisual;
import pgui.visual.PComponent;

public class VisualWindowBorderTop extends PComponent {

	public VisualWindowBorderTop(PVisual visual) {
		super(visual);
		
		this.setRelativeWidth(100);
		this.setHeight(3);
	}
	
	// Mouse Events
	@Override
	public void onMouseMoved(MouseEvent event, MouseEvent lastEvent) {
		super.onMouseMoved(event, lastEvent);
		setCursor(Cursor.N_RESIZE_CURSOR);
		mouseLock(false);
	}
	
	@Override
	public void onMouseExited(MouseEvent event, MouseEvent lastEvent) {
		super.onMouseExited(event, lastEvent);
		setCursor(Cursor.DEFAULT_CURSOR);
		mouseLock(false);
	}
	
	@Override
	public void onMousePressed(MouseEvent event) {
		super.onMousePressed(event);
		mouseLock(true);
	}
	
	@Override
	public void onMouseReleased(MouseEvent event) {
		super.onMouseReleased(event);
		mouseLock(false);
		setCursor(Cursor.DEFAULT_CURSOR);
	}
	
	@Override
	public void onMouseDragged(MouseEvent event, MouseEvent lastEvent) {
		super.onMouseDragged(event, lastEvent);
		
		int resizeY = - event.getY() + lastEvent.getY();
		this.getParent().setHeight(this.getParent().getHeight() + resizeY);
		this.getParent().setY(this.getParent().getY() - resizeY);
		
		if(this.getParent().getHeight() < VisualWindow.MINIMUM_HEIGHT)
			this.getParent().setHeight(VisualWindow.MINIMUM_HEIGHT);
	}
	
	// Paint Events
	@Override
	public void onPaint(Graphics2D g) {
		super.onPaint(g);
		
		g.setColor(Color.white);
		g.drawRect(0, 0, this.getLastWidth(), 0);
	}
}
